package org.example.seata.bs.api.feign.product;

import org.example.seata.bs.api.dto.order.OrderInfoDto;
import org.example.seata.bs.api.entity.product.Product;
import org.example.seata.bs.api.feign.product.factory.RemoteProductServiceFallbackFactory;
import org.example.seata.common.core.constant.ServiceModuleConst;
import org.example.seata.common.core.util.ApiResp;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * @author hzq
 * @date 2021/11/18 14:34
 */
@FeignClient(
        value = ServiceModuleConst.PRODUCT_SERVICE,
        contextId = "remoteProductService",
        fallbackFactory = RemoteProductServiceFallbackFactory.class
)
public interface RemoteProductService {

    /**
     * 通过产品id 查询产品信息
     *
     * @param productId 产品id
     * @return 产品信息
     */
    @GetMapping("/product/{productId}")
    ApiResp<Product> getById(@PathVariable("productId") Integer productId);

    /**
     * 减去产品虚拟库存
     *
     * @param orderInfoDtoList 详情
     */
    @PutMapping("/product/minusProductVirtualInventory")
    ApiResp<Boolean> minusProductVirtualInventory(@RequestBody List<OrderInfoDto> orderInfoDtoList);

    /**
     * 加上产品虚拟库存
     *
     * @param orderInfoDtoList 详情
     */
    @PutMapping("/product/plusProductVirtualInventory")
    ApiResp<Boolean> plusProductVirtualInventory(@RequestBody List<OrderInfoDto> orderInfoDtoList);

}
